package com.yiwyn.advisordemo.config;

import com.yiwyn.advisordemo.advice.TaskAdvice;
import com.yiwyn.advisordemo.anno.Task;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.annotation.AnnotationMatchingPointcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TaskConfig {

    @Bean
    public DefaultPointcutAdvisor taskAdvisor(TaskAdvice taskAdvice) {
        AnnotationMatchingPointcut matchingPointcut = AnnotationMatchingPointcut.forMethodAnnotation(Task.class);
        DefaultPointcutAdvisor defaultPointcutAdvisor = new DefaultPointcutAdvisor();
        defaultPointcutAdvisor.setAdvice(taskAdvice);
        defaultPointcutAdvisor.setPointcut(matchingPointcut);
        return defaultPointcutAdvisor;
    }
}